#! /bin/sh

# curl -fsSL https://developer.spinframework.com/downloads/install.sh | bash -s -- -v canary

# curl -fsSL install.sh | bash -s -- -v canary

get_spin_cli() {
	repo="spinframework/spin"
	cli="spin-canary-linux-amd64.tar.gz"
	cli_name="spin"
	sudo rm -rf /usr/local/bin/${cli_name}
	mkdir demo && cd demo
	wget https://ghproxy.net/https://github.com/${repo}/releases/download/canary/${cli}
	# wget https://hub.fastgit.org/${repo}/releases/download/canary/${cli}
	# wget https://github.com/${repo}/releases/download/canary/${cli}

	tar -zxvf ${cli}
	sudo mv ${cli_name} /usr/local/bin/
	cd ..
	rm -rf demo
	echo "spin cli install successfully"
}

get_spin_plugins() {
	spin plugins update
	spin plugins install kube --yes
	spin plugins install pluginify --yes
	spin plugins install js2wasm --yes
	spin plugins install gh --yes
	spin plugin install otel --yes
	spin plugins list --installed
	spin otel setup --aspire
	# spin plugins install --yes --url https://github.com/spinframework/spin-trigger-command/releases/download/canary/trigger-command.json
	# git clone --depth 1 https://github.com/itowlson/spin-pluginify
	# cargo run -r -- --install

	# git clone --depth 1 https://github.com/spinkube/spin-plugin-kube
	# make && make install
	echo "spin plugin install successfully"
}

get_spin_templates() {
	spin templates install --git https://github.com/spinframework/spin --update
	spin templates install --git https://github.com/spinframework/spin-js-sdk --update
	spin templates install --git https://github.com/gmlewis/spin-moonbit-sdk --update

	# spin templates install --git https://github.com/spinkube/spin-trigger-mqtt --upgrade
	# spin templates install --git https://github.com/spinframework/spin-kv-explorer --upgrade
	# spin templates install --upgrade --git https://github.com/spinframework/spin-trigger-command
	# rustup target add wasm32-wasi

	# spin new -t http-js
	echo "spin templates install successfully"
}

get_spin_cli
get_spin_plugins
get_spin_templates

# 安装可视化面板 打开 清理
# spin otel setup --aspire
# spin otel open aspire
# spin otel cleanup
